//
//  PullAllCommon.swift
//  JKConsole
//
//  Created by 姜奎 on 2020/11/20.
//  Copyright © 2020 JK. All rights reserved.
//

import Foundation

class PullAllCommon: PullCommon {
    override func run(options: ConsoleOptions) {
        
        let pro = Project()
        let project = Project(directoryPath: pro.rootPath)
        if pro.rootPath != pro.directoryPath {
            self.pull(pro: project, options: options)
        }
        do {
            let data = try Data(contentsOf: URL(fileURLWithPath: project.recordListPath))
            let recordList = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as! Array<String>
            print(Colors.green("【\(project.name)】Modulefile.recordList 读取成功"))
            for record in recordList {
                let pro1 = Project(directoryPath: "\(project.checkoutsPath)/\(record)")
                self.pull(pro: pro1, options: options)
            }
        } catch {
            print(Colors.red("【\(project.name)】Modulefile.recordList 读取失败"))
        }
    }
}
